package com.shop2cn.iapi.productcategory.testcase;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.shop2cn.iapi.productcategory.parameter.ProductCategoryDto;
import com.shop2cn.iapi.productcategory.service.GetAllProductCategoryCall;
import com.ymt.core.tool.FormatUtil;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.database.mongo.BuyerProductShop2cnWapper;

/**
 * FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_GetAllProductCategory {
	private static GetAllProductCategoryCall GetAllProductCategoryCall;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取所有的商品品类信息");
	}

	@Before
	public void caseUp() {
		// 旧站点
//		GetAllProductCategoryCall = new GetAllProductCategoryCall(EnvSetup.getSystemUrl("productcategory_api"));
//		新站點
		GetAllProductCategoryCall = new GetAllProductCategoryCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(GetAllProductCategoryCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_GetAllProductCategory_001() {
		Logger.start(true, "获取所有的商品品类信息");
		try {
			List<Integer> brandIdList = new ArrayList<Integer>();
			GetAllProductCategoryCall.callService();
			Logger.verifyEquals("200", GetAllProductCategoryCall.getString("Code"), "验证Code");
			JsonArray data = GetAllProductCategoryCall.getData();
			BuyerProductShop2cnWapper np= new BuyerProductShop2cnWapper();
			for (JsonElement jsonElement : data) {
				ProductCategoryDto pd = (ProductCategoryDto) FormatUtil.GSONToObject(jsonElement.getAsJsonObject().toString(), ProductCategoryDto.class);
				Map<String, Object> m =np.getProductCatalogInfoByCid(pd.getCategoryId().toString()).get(0);
				Logger.verifyEquals(m.get("CategoryEnName"), pd.getCategoryEnName(), "验证CategoryEnName");
				Logger.verifyEquals(m.get("CategoryName"), pd.getCategoryName(), "验证CategoryName");
				Logger.verifyEquals(new BigDecimal( m.get("CategorySort").toString()).intValue(), pd.getCategorySort(), "验证CategorySort");
				Logger.verifyEquals(new BigDecimal( m.get("MasterCategoryId").toString()).intValue(), pd.getMasterCategoryId(), "验证MasterCategoryId");
				Logger.verifyEquals(new BigDecimal(m.get("Level").toString()).intValue(), pd.getLevel(), "验证Level");
				Logger.verifyEquals(new BigDecimal(m.get("ProductsNum").toString()).intValue(), pd.getProductsNum(), "验证ProductsNum");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}